<?php	 
class Seguridad 
{
	protected static $_cadena;

    public static function Cifrar($cadena)
	{
		self::$_cadena=$cadena;
		return trim(base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, SEMILLA, self::$_cadena, MCRYPT_MODE_ECB, mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND))));
	}
 
	public static function Descifrar($cadena)
	{
		self::$_cadena=$cadena;
		return trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, SEMILLA, base64_decode(self::$_cadena), MCRYPT_MODE_ECB, mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND)));
	}
	
	public static function LimpiarFormulario($cadena)
	{
		return addslashes(Limpiar($cadena));
	}
	
	public static function LimpiarInput($cadena)
    {
		$busqueda=array("@SELECT@",
						"@COPY@",	
						"@DELETE@",
						"@DUMP@",
						"@OR@",
						"@LIKE@",
						"@COUNT@",
						"@INTO@",
						"@DROP@",
						"@select@",
						"@copy@",	
						"@delete@",	
						"@dump@",
						"@or@",
						"@like@",
					    "@NULL@",
						"@count@",
						"@into@",
						"@drop@",
						"@null@",							
						"@OR '1'='1'@",
					    "@or '1'='1'@",
						"@=@",
						"@-1@",		
						"@/@",
						"@;@",
						"@<script[^>]*?>.*?</script>@si",
						"@<style[^>]*?>.*?</style>@siU",
						"@<[\/\!]*?[^<>]*?>@si",
						"@<![\s\S]*?--[ \t\n\r]*>@");	
		$salida= preg_replace($busqueda,"",$cadena);
		return $salida;
	}	
		
	public static function Cadena($cadena)
	{
		return (string)$cadena;
	}
	
	public static function Entero($cadena)
	{
		return intval($cadena);
	}
	
	public static function Decimal($cadena)
	{ 
		return floatval($cadena);
	}
		
	public static function EvitarDuplicados($unico)
	{
        if(isset($_SESSION['unico'])) 
		{
            if ($unico == $_SESSION['unico']) 
			{
                return false;
            } 
			else 
			{
                $_SESSION['unico'] = $unico;
                return true;
            }
        } 
		else 
		{
            $_SESSION['unico'] = $unico;
            return true;
        }
    }
}	

?>